home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-27 | 4.2 KB | 152 lines | [TEXT/CWIE] |
- /* SK8 © 1997 Apple Computer, Inc.
- This code is protected under the current SK8 License
- See http://sk8.research.apple.com/ for more information
- Apple Research Laboratories
- */
-
- import java.util.*;
- import java.awt.*;
-
- class dragresizeeventmode extends eventmode {
- int mouseh = 0;
- int mousev = 0;
- boolean resizeRatherThanDrag = false;
- boolean dispatchDragEvents = false;
- actor myactor = null;
- actor drageventactor = null;
-
- // methods.
-
- public dragresizeeventmode (actor act, boolean resizep, boolean dragevents) {
- super();
- this.mouseh = Mouse.x;
- this.mousev = Mouse.y;
- this.myactor = act;
- this.drageventactor = null;
- this.resizeRatherThanDrag = resizep;
- this.dispatchDragEvents = dragevents;
- }
-
- public void handleidle (Event e) {
- int newmouseh = Mouse.x;
- int newmousev = Mouse.y;
- if ((newmouseh != mouseh) || (newmousev != mousev)) {
- if (this.resizeRatherThanDrag) {
- this.myactor.setboundsrect(0,0,newmouseh - mouseh, newmousev - mousev, true, true, false);
- } else {
- this.myactor.setlocation(newmouseh - mouseh, newmousev - mousev, true, true);
- //if (dispatchDragEvents == true) {
- // if (drageventactor != null) drageventactor.draggingmousewithin(myactor);
- // this.changeeventactor(myactorwindow.pointonwhichactor(newmouseh, newmousev, myactor));
- //}
- //if (myactor.container() instanceof actor)
- // ((actor)myactor.container()).forcefullredraw();
- }
- mouseh = newmouseh;
- mousev = newmousev;
- }
- }
-
- public void handlemousedown (Event e) {
- }
-
- public void handleactivate (Event e, actor oldwindow) {
- }
-
- public void handlemouseup (Event e) {
- if (this.resizeRatherThanDrag) {
- this.myactor.resizedone();
- } else {
- this.myactor.dragged();
- //this.myactor.drop();
- }
- this.myactor.mouseup();
- this.exitmode();
- }
-
- public void handlekeydown (Event e) {
- }
-
- public void handlekeyup (Event e) {
- }
-
- public void resume () {
- }
-
- public void suspend () {
- }
-
- public void activate () {
- }
-
- public void deactivate () {
- }
-
- /*
- //======================================================================
- // Dispatching mouseenter and mouseleave...
- //======================================================================
-
-
- // call mouseenter on each item in the path from commoncontainer to this (the actor).
- // use recursion to make the reverse calling happen.
-
- void reverseddispatchmouseenter (actor act, actor commoncontainer) {
- if (act != commoncontainer) {
- if ((act.container() != null) && (commoncontainer != null)) {
- this.reverseddispatchmouseenter(act.container(), commoncontainer);
- act.draggingmouseenter(myactor);
- }
- }
- }
-
- // this = the old actor, the one that should get a mouseleave.
-
- void dispatchmouseenterandleave(actor oldactor, actor newactor) {
- int olddepth = ((actor) oldactor).depth();
- int newdepth = ((actor) newactor).depth();
- actor commoncontainer;
- // if the actor is no longer on the stage, do not send mouseleaves to it.
- if (newdepth == 0)
- this.reverseddispatchmouseenter(newactor, sk8.stage);
- else {
- // [1] find common container.
- if (olddepth > newdepth)
- commoncontainer = ((actor) oldactor).findcommoncontainer(newactor, olddepth - newdepth);
- else
- commoncontainer = ((actor) newactor).findcommoncontainer(oldactor, newdepth - olddepth);
- // [2] Dispatch mouseleave (from deepest up).
- while (true) {
- if ((oldactor == commoncontainer) || (oldactor == null)) break;
- oldactor.draggingmouseleave(myactor);
- oldactor = oldactor.container();
- }
- // [3] set the event actor.
- drageventactor = newactor;
- // [4] Dispatch mouseenter (from shallowest up).
- this.reverseddispatchmouseenter(newactor, commoncontainer);
- }
- }
-
- // When the oldActor was nil, we throw up our arms. We just set the eventActor and
- // dispatch mouseEnter to everything from the Stage up to the new actor.
-
- void justdomouseenters (actor act) {
- // [1] set the event actor.
- drageventactor = act;
- // [2] send the mouse enters.
- this.reverseddispatchmouseenter(act, sk8.stage);
- }
-
- // this is the new event target.
-
- void changeeventactor (actor act) {
- if (act != null) {
- if (drageventactor != null)
- this.dispatchmouseenterandleave(drageventactor ,act);
- else
- this.justdomouseenters(act);
- }
- }
- */
- }